<template>
	<div class="outerFrame">
		<div class="operator">
			<el-button type="primary" icon="el-icon-plus" @click="toSave()">添加</el-button>
			<el-button type="danger" icon="el-icon-delete" @click="remove()">批量删除</el-button>
		</div>
		<div class="dataTable" v-if="listData">
			<el-table :data="listData.records" stripe border height="85%" v-loading="listLoading" @selection-change="selectionChange">
						<el-table-column type="selection" width="55" fixed="left"></el-table-column>
						<el-table-column prop="mid" label="成员ID"></el-table-column>
						<el-table-column prop="code" label="单号：200810100010
                V/S+单号"></el-table-column>
						<el-table-column prop="jdtm" label="下单时间"></el-table-column>
						<el-table-column prop="phone" label="电话"></el-table-column>
						<el-table-column prop="eid" label="企业id"></el-table-column>
						<el-table-column prop="state" label="状态：1待接单，2，已接单，3，已配送，4，已拒单"></el-table-column>
						<el-table-column prop="sendway" label="配送方式:达达、美团、自配送"></el-table-column>
						<el-table-column prop="sendtm" label="配送时间"></el-table-column>
						<el-table-column prop="eaddrs" label="公司地址"></el-table-column>
						<el-table-column prop="maddrs" label="员工地址"></el-table-column>
						<el-table-column prop="cost" label="金额"></el-table-column>
						<el-table-column prop="exptxt" label="订单项[订单项id]"></el-table-column>
						<el-table-column prop="remark" label="备注"></el-table-column>
				<el-table-column label="操作" fixed="right" width="200px">
					<template slot-scope="scope">
						<div class="dataTable-operator">
							<el-button size="mini" icon="el-icon-edit" @click="toUpdate(scope.$index, scope.row)">编辑</el-button>
							<el-button size="mini" type="danger" icon="el-icon-delete" @click="remove(scope.$index, scope.row)">删除</el-button>
						</div>
					</template>
				</el-table-column>
			</el-table>
			<div class="pageBar">
				<el-pagination
					@size-change="sizeChange"
					@current-change="currentChange"
					:total="listData.total"
					:page-size="request.page.size"
					:current-page="request.page.current"
					:layout="constant.page.layout"
					:page-sizes="constant.page.pageSizes"
				></el-pagination>
			</div>
		</div>
		<editDialog :parameter="editParameter" :isDisplay.sync="editDisplay"></editDialog>
	</div>
</template>
<script>
import utils from 'util/utils.js';
import constant from 'util/constant.js';
import api from 'api/order/orders/orders.js';
import editDialog from './edit.vue';
export default {
	name: 'orders',
	data() {
		return {
			listLoading: true,
			listData: {},
			editDisplay: false,
			editParameter: {},
			constant: constant,
			request: utils.newRequest()
		};
	},
	components: {
		editDialog
	},
	methods: {
		//改变选择项
		selectionChange(val) {
			//清空
			this.request.param.ids = [];
			for (let item of val) {
				this.request.param.ids.push(item.id);
			}
		},
		//改变每页显示数量
		sizeChange(val) {
			this.request.page.size = val;
			this.list();
		},
		//改变现在的页码
		currentChange(val) {
			this.request.page.current = val;
			this.list();
		},
		//获取数据
		list() {
			this.listLoading = true;
			api.list(this.request, response => {
				this.listData = response.data;
				this.listLoading = false;
			});
		},
		//去添加
		toSave() {
			this.editDisplay = true;
			this.editParameter = {};
		},
		//去编辑
		toUpdate(index, row) {
			this.editDisplay = true;
			this.editParameter = {
				id: row.id
			};
		},
		//删除
		remove(index, row) {
			//单个删除
			if (row) {
				this.request.param.ids = [row.id];
			}
			if (!this.request.param.ids || this.request.param.ids.length == 0) {
				utils.msg.info('请选择至少一行');
				return;
			}
			utils.confirm('确定删除吗？', '提示', () => {
				api.remove(
					this.request,
					response => {
						utils.msg.success(response.msg);
						this.list();
					},
					response => {
						utils.msg.warning(response.msg);
					}
				);
			});
		},
		//搜索
		search() {
			this.list();
		},
		//清空搜索框
		clearSearchVal() {
			this.request.param = {};
		}
	},
	mounted() {
		this.list();
	}
};
</script>

<style lang="scss">
@import '~common/custom/css/common.scss';
</style>
